﻿@{
    ViewBag.Title = "字典管理";
    Layout = "_Index";
}
<link href="~/plugins/jquery-treegrid/css/jquery.treegrid.min.css" rel="stylesheet" />
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="ibox ">
        <div class="ibox-content">
            <div id="toolbar" class="btn-group">

            </div>
            <table id="dicTable"></table>
        </div>

    </div>
</div>
@section scripts
{
    <script src="~/plugins/bootstrapTableTree/bootstrap-table-treegrid.js"></script>
    <script src="~/plugins/jquery-treegrid/jquery.treegrid.min.js"></script>

    <script>
        var $table;
        $(function () {
            loadGrid();
        });

        function loadGrid() {
          
           $table = $("#dicTable").bootstrapTable({
               url:'/admin/sysdic/GetTreeGrid',
                height: $(window).height(),
                striped: true,
               sidePagination: 'server',
               idField: 'id',
               uniqueId: 'id',
                columns: [
                    {field: 'ck',checkbox: true},
                    { field: 'dic_name', title: '字典名称', align: 'left' },
                    { field: 'sort_num', title: '排序', align: 'center' },
                    { field: 'dic_code', title: '字典编码', align: 'center' },
                    { field: 'remark', title: '备注', align: 'center' },
                    {
                        field: 'id', title: '操作', align: 'center',
                        formatter: renderOpts
                    }
                ],
                treeShowField: 'dic_name',
                parentIdField: 'parent_id',
               onLoadSuccess: function (data) {
                    $table.treegrid({
                        // initialState: 'collapsed',
                        treeColumn: 1,
                        // expanderExpandedClass: 'glyphicon glyphicon-minus',
                        // expanderCollapsedClass: 'glyphicon glyphicon-plus',
                        onChange: function() {
                            $table.bootstrapTable('resetWidth');
                        }
                    });
                }
                // bootstrap-table-treetreegrid.js 插件配置
           });
            jutils.initToolBarRole('#toolbar', true);
        }

        function renderOpts(v, r, i) {
            var html = jutils.initToolBarRow(v);
            return html;
        }
        function add() {
            jutils.dialog('字典信息',
                '/admin/sysdic/form',null,null,
                function () {
                   
                });
        }

        function edit(obj) {
            var id = $(obj).data('id');
            jutils.dialog('字典信息',
                '/admin/sysdic/form',
                { id: id }, null,
                function () {
                    $table.bootstrapTable('refresh');

                });
        }

        function del(obj) {
            var id = $(obj).data('id');

            jutils.confirm('确认删除吗',
                function () {
                    jutils.ajaxGet('/admin/sysdic/del',
                        { ids: id },
                        function () {
                            $table.bootstrapTable('refresh');
                            
                        });
                });
        }
    </script>


}